package com.hq.fxh.No2_BBS.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.hq.fxh.No2_BBS.Activity.PlateDetialActivity;
import com.hq.fxh.No2_BBS.Activity.PlateSelectActivity;
import com.hq.fxh.No2_BBS.Adapter.Ladapter_PlateName;
import com.hq.fxh.No0_ChengQu.Fragment.BaseFragment;
import com.hq.fxh.Modle.PlateSoreModle;
import com.hq.fxh.R;

import java.util.List;

/**
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/8/18
 * @Email xlwenhao1858@sina.com
 */


public class Plate_Name_Fragment extends BaseFragment {
    protected View rootView;
    protected ListView listPlatName;
    List<PlateSoreModle.DataBean.ItemsBean> data;
    int type = 1, firstID;

    public void setType(int type) {
        this.type = type;
    }

    public void setData(List<PlateSoreModle.DataBean.ItemsBean> data, int firstID) {
        this.data = data;
        this.firstID = firstID;
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_plate_name;
    }

    @Override
    protected void initData() {
        Ladapter_PlateName adapter = new Ladapter_PlateName(data, new Ladapter_PlateName.PlateNameCallBack() {
            @Override
            public void onCallFocus(View view, int position, Object data) {

            }

            @Override
            public void onCallName(View view, int position, Object data) {
                PlateSoreModle.DataBean.ItemsBean dataBean = (PlateSoreModle.DataBean.ItemsBean) data;
                if (type == 2) {
                    PlateSelectActivity activity = (PlateSelectActivity) getActivity();
                    activity.setSecondSort(dataBean.getId(), dataBean.getCategory());
                    activity.setPlateSeclect(data.toString());
                } else {
                    Intent intent = new Intent(getContext(), PlateDetialActivity.class);
                    intent.putExtra("firstID", firstID);
                    intent.putExtra("secondID", dataBean.getId());
                    startActivity(intent);
                }
            }
        });
        listPlatName.setAdapter(adapter);
    }

    @Override
    protected void findView(View rootView) {
        listPlatName = (ListView) rootView.findViewById(R.id.list_Plat_Name);
    }
}
